function backDeviceGroup() {
	window.location.href = 'userParameterAdd.jsp';

}

function load() {
	var x = document.getElementById("abc");
	x.selectedIndex = -1;
}
load()
var ticklength;
var idtick = []; //			全体打钩
function checkInput() {
	var tick = $(".tick").css("display");
	if(tick == "none") {
		$(".tick").show();
		tickId = ticklength;
		tickaId = somearray[0];
		somearray = idtick;
	} else if(tick == "block") {
		$(".tick").hide();
		$(".tick").hide();
		$(".tick_block ").hide();
		tickId = 0;
		somearray = [];
		tickaId = somearray[0];
	}
}
//			单独打钩
var tickId = 0;
var tickaId = '';
var somearray = []

function removeByValue(arr, val) {
	for(var i = 0; i < arr.length; i++) {
		if(arr[i] == val) {
			arr.splice(i, 1);
			break;
		}
	}
}

function checkInputA(data) {
	var ticka = "tick_" + data.id
	var tickBlock = document.getElementById(ticka);
	if(tickBlock.style.display == "block") {
		tickBlock.style.display = "none";
		removeByValue(somearray, data.id);
		tickId = tickId - 1;
		tickaId = somearray[0];
	} else if(tickBlock.style.display == "" || tickBlock.style.display == "none") {
		tickBlock.style.display = "block";
		removeByValue(somearray, data.id);
		somearray.push(data.id);
		tickaId = somearray[0];
		tickId = tickId + 1;
	}
}
$(".device_edit").click(function() {
	if(tickId == 0) {
		alert("请选择你要编辑的记录！")
	} else if(tickId == 1) {
		sessionStorage.setItem("tickId", tickId);
		sessionStorage.setItem("tickaId", tickaId);
		window.location.href = 'userParameterRevisejsp.jsp';
	} else if(tickId > 1) {
		alert("一次只能编辑一条记录！")
	}
})
$(".userParameter_delete").click(function() {

	var param = {
		session: $.Cookie("session"),
		userId: $.Cookie("userId"),
		companyId: $.Cookie("companyId"),
		paramId: tickaId,
		flag: '1',
	}

	$.ajax({
		url: 'paramTypeOperation',
		type: 'POST',
		data: param,
		dataType: 'json',
		success: function(data) {
			if(data.errorCode == 0) {
				alert("听说你成功了！")
				window.location.href = 'userParameter.jsp';
			} else if(data.errorCode == -6) {
				alert("登录超时！")
				top.location.href = 'index.jsp';
			} else if(data.errorCode == -301) {
				alert("基础数据已存在！请勿重新添加！")
			} else {
				alert("请重试！")
			};
		},
		error: function(err) {
			alert("连接服务器失败！请重新提交！");
			top.location.href = 'index.jsp';

		}
	});

})

$.ajax({
	url: 'paramTypeList',
	type: 'POST',
	data: {
		session: $.Cookie("session"),
		userId: $.Cookie("userId"),
		companyId: $.Cookie("companyId"),
		index: 0,
		page: 10
	},
	dataType: 'json',
	success: function(data) {
		$.each(data.result.paramTypeList, function(i, value) {
			if(data.result.paramTypeList[i].type == "ORG_TYPE") {
				if(i % 2 == 0) {
					var error_tpl = '<div class="userParameter_content_contenta"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"> <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userParameter_content_header_div">机构类型</div> <div class="userParameter_content_header_div">' + value.paramKey + '</div> <div class="userParameter_content_header_div">' + value.paramValue + '</div> <div  class="userParameter_content_header_div manage_content_header_div_four">' + value.paramDesc + '</div> </div>'

				} else {
					var error_tpl = '<div class="userParameter_content_content"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"> <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userParameter_content_header_div">机构类型</div> <div class="userParameter_content_header_div">' + value.paramKey + '</div> <div class="userParameter_content_header_div">' + value.paramValue + '</div> <div  class="userParameter_content_header_div manage_content_header_div_four">' + value.paramDesc + '</div> </div>'

				}

			} else {
				if(i % 2 == 0) {
					var error_tpl = '<div class="userParameter_content_contenta"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"> <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userParameter_content_header_div">设备类型</div> <div class="userParameter_content_header_div">' + value.paramKey + '</div> <div class="userParameter_content_header_div">' + value.paramValue + '</div> <div  class="userParameter_content_header_div manage_content_header_div_four">' + value.paramDesc + '</div> </div>'

				} else {
					var error_tpl = '<div class="userParameter_content_content"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"> <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userParameter_content_header_div">设备类型</div> <div class="userParameter_content_header_div">' + value.paramKey + '</div> <div class="userParameter_content_header_div">' + value.paramValue + '</div> <div  class="userParameter_content_header_div manage_content_header_div_four">' + value.paramDesc + '</div> </div>'

				}

			}
			ticklength = data.result.paramTypeList.length;
			idtick.push(value.id)
			$(".pageParameter").append(error_tpl)
		});

		$('.pageParametera').Paging({
			pagesize: 10,
			count: data.result.count,
			toolbar: true,
			callback: function(page, size, count) {
				$(".pageParameter").html("")
				$.ajax({
					url: 'paramTypeList',
					type: 'POST',
					data: {
						session: $.Cookie("session"),
						userId: $.Cookie("userId"),
						companyId: $.Cookie("companyId"),
						index: page - 1,
						page: 10
					},
					dataType: 'json',
					success: function(data) {
						$.each(data.result.paramTypeList, function(i, value) {
							if(data.result.paramTypeList[i].type == "ORG_TYPE") {

								var error_tpl = '<div class="userParameter_content_contenta"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"> <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userParameter_content_header_div">机构类型</div> <div class="userParameter_content_header_div">' + value.paramKey + '</div> <div class="userParameter_content_header_div">' + value.paramValue + '</div> <div  class="userParameter_content_header_div manage_content_header_div_four">' + value.paramDesc + '</div> </div>'
							} else {

								var error_tpl = '<div class="userParameter_content_content"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"> <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userParameter_content_header_div">设备类型</div> <div class="userParameter_content_header_div">' + value.paramKey + '</div> <div class="userParameter_content_header_div">' + value.paramValue + '</div> <div  class="userParameter_content_header_div manage_content_header_div_four">' + value.paramDesc + '</div> </div>'
							}
							ticklength = data.result.paramTypeList.length;
							idtick.push(value.id)
							$(".pageParameter").append(error_tpl)
						});

					},
					error: function(err) {
						alert("连接服务器失败！请重新提交！");
						top.location.href = 'index.jsp';
					}
				});
			}

		})
	},
	error: function(err) {
		alert("连接服务器失败！请重新提交！");
		top.location.href = 'index.jsp';
	}
});

function inquiry() {
	var param;
	if($("#abc").val() == '' || $("#abc").val() == null) {
		if($("#paramKey").val() == '' || $("#paramKey").val() == null) {
			param = {
				session: $.Cookie("session"),
				userId: $.Cookie("userId"),
				companyId: $.Cookie("companyId"),
				index: 0,
				page: 10,
			}

		} else {
			param = {
				session: $.Cookie("session"),
				userId: $.Cookie("userId"),
				companyId: $.Cookie("companyId"),
				index: 0,
				page: 10,
				paramKey: $("#paramKey").val(),
			};
		}
	} else if($("#paramKey").val() == '' || $("#paramKey").val() == null) {
		if($("#abc").val() == '' || $("#abc").val() == null) {
			param = {
				session: $.Cookie("session"),
				userId: $.Cookie("userId"),
				companyId: $.Cookie("companyId"),
				index: 0,
				page: 10
			}

		} else {
			param = {
				session: $.Cookie("session"),
				userId: $.Cookie("userId"),
				companyId: $.Cookie("companyId"),
				index: 0,
				page: 10,
				type: $("#abc").val()
			};
		}

	} else {
		param = {
			session: $.Cookie("session"),
			userId: $.Cookie("userId"),
			companyId: $.Cookie("companyId"),
			index: 0,
			page: 10,
			type: $("#abc").val(),
			paramKey: $("#paramKey").val()
		};
	};
	$.ajax({
		url: 'paramTypeList',
		type: 'POST',
		data: param,
		dataType: 'json',
		success: function(data) {
			$(".pageParameter").html("");
			$(".pageParametera").html("");
			$.each(data.result.paramTypeList, function(i, value) {
				if(data.result.paramTypeList[i].type == "ORG_TYPE") {
					if(i % 2 == 0) {
						var error_tpl = '<div class="userParameter_content_contenta"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"> <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userParameter_content_header_div">机构类型</div> <div class="userParameter_content_header_div">' + value.paramKey + '</div> <div class="userParameter_content_header_div">' + value.paramValue + '</div> <div  class="userParameter_content_header_div manage_content_header_div_four">' + value.paramDesc + '</div> </div>'
					} else {
						var error_tpl = '<div class="userParameter_content_content"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"> <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userParameter_content_header_div">机构类型</div> <div class="userParameter_content_header_div">' + value.paramKey + '</div> <div class="userParameter_content_header_div">' + value.paramValue + '</div> <div  class="userParameter_content_header_div manage_content_header_div_four">' + value.paramDesc + '</div> </div>'
					}
				} else {
					if(i % 2 == 0) {
						var error_tpl = '<div class="userParameter_content_contenta"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"> <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userParameter_content_header_div">设备类型</div> <div class="userParameter_content_header_div">' + value.paramKey + '</div> <div class="userParameter_content_header_div">' + value.paramValue + '</div> <div  class="userParameter_content_header_div manage_content_header_div_four">' + value.paramDesc + '</div> </div>'
					} else {
						var error_tpl = '<div class="userParameter_content_content"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"> <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userParameter_content_header_div">设备类型</div> <div class="userParameter_content_header_div">' + value.paramKey + '</div> <div class="userParameter_content_header_div">' + value.paramValue + '</div> <div  class="userParameter_content_header_div manage_content_header_div_four">' + value.paramDesc + '</div> </div>'
					}
				}
				ticklength = data.result.paramTypeList.length;
				idtick.push(value.id)
				$(".pageParameter").append(error_tpl)
			});
			$('.pageParametera').Paging({
				pagesize: 10,
				count: data.result.count,
				toolbar: true,
				callback: function(page, size, count) {
					$(".pageParameter").html("")
					$.ajax({
						url: 'paramTypeList',
						type: 'POST',
						data: param,
						dataType: 'json',
						success: function(data) {
							if(data.errorCode == 0) {
								$.each(data.result.paramTypeList, function(i, value) {
									if(data.result.paramTypeList[i].type == "ORG_TYPE") {
										var error_tpl = '<div class="manage_content_content"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"> <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="manage_content_header_div">机构类型</div> <div class="manage_content_header_div">' + value.paramKey + '</div> <div class="manage_content_header_div">' + value.paramValue + '</div> <div  class="manage_content_header_div manage_content_header_div_four">' + value.paramDesc + '</div> </div>'
									} else {
										var error_tpl = '<div class="manage_content_content"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"> <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="manage_content_header_div">设备类型</div> <div class="manage_content_header_div">' + value.paramKey + '</div> <div class="manage_content_header_div">' + value.paramValue + '</div> <div  class="manage_content_header_div manage_content_header_div_four">' + value.paramDesc + '</div> </div>'
									}
									ticklength = data.result.paramTypeList.length;
									idtick.push(value.id)
									$(".pageParameter").append(error_tpl)
								});

							} else if(data.errorCode == -6) {
								alert("登录超时！")
								top.location.href = 'index.jsp';

							} else {
								alert("请重试！");
							}

						},
						error: function(err) {
							alert("连接服务器失败！请重新提交！");
							top.location.href = 'index.jsp';

						}
					});
				}

			})
		},
		error: function(err) {
			alert("连接服务器失败！请重新提交！");
			top.location.href = 'index.jsp';

		}
	});
}

function cleanUp() {
	load();
	$("#paramKey").val("");

}

autodivheight();

function autodivheight() { //函数：获取尺寸
	//获取浏览器窗口高度
	var winHeight = 0;
	if(window.innerHeight)
		winHeight = window.innerHeight;
	else if((document.body) && (document.body.clientHeight))
		winHeight = document.body.clientHeight;
	//通过深入Document内部对body进行检测，获取浏览器窗口高度
	if(document.documentElement && document.documentElement.clientHeight)
		winHeight = document.documentElement.clientHeight;
	//DIV高度为浏览器窗口的高度

	a = winHeight - 260;
	if(a < 0) {
		a = 0
		$(".pageParameter").css("height", a);
		//		$(".pageTool").css("min-height", 410);

	} else {
		$(".pageParameter").css("height", a);
		//		$(".pageTool").css("min-height", 410);

	}

	//				document.getElementById("test").style.height = winHeight / 2 + "px";
}
window.onresize = autodivheight; //浏览器窗口发生变化时同时变化DIV高度